<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="CustomAlertBehavior.aspx.cs" Inherits="AlertBehavior_CustomAlertBehavior"
	Title="CustomAlertBehavior - ModWatch" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
	<script type="text/javascript">
		function verifyExit(sender, e)
		{
			var result = prompt("Unsaved changes have been made.  Do you want to" +
								" leave the page?  Enter 'Yes' to continue.", "");
			if (result == null)
			{
				e.set_cancel(true);
				return;
			}

			while (result != "yes")
			{
				result = prompt("Enter 'Yes' to continue.", "");
				if (result == null)
				{
					e.set_cancel(true);
					return;
				}
			}
		}
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" Runat="Server">

	<h2>CustomAlertBehavior Control</h2>

	<p>
		The CustomAlertBehavior control notifies the
		user that changes exists in a custom way that
		is defined by the developer.
	</p>

	<p>
		This sample page will define a CustomAlertBehavior control that
		requires the user to enter text into a prompt dialog box before
		leaving a page if changes exist.
	</p>

	<p>
		Below is the CustomAlertBehavior define on the page:
	</p>

	<p>
		&lt;mw:CustomAlertBehavior ID="cabTestAlert" runat="server" <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			ClientNotifyFunction="verifyExit" />
	</p>

	<p>
		The CustomAlertBehavior control contains a ClientNotifyFunction property that
		specifies a javascript function that determines whether the ModWatch framework
		should cancel the user's request to exit the page.  This function takes two
		parameters.  The first is the CustomAlertBehavior control for which the
		evaluation is being made.  The second is a CustomAlertEventArgs object that
		defines two properties: the readonly modAlertBehavior property retrieves the
		the modAlertBehavior object that fired the CustomAlertBehavior; the read/write
		cancel property gets or sets a value indicating whether or not the ModWatch
		framework should cancel the user's request to exit the page.
	</p>

	<p>
		function verifyExit(sender, e) <br />
		{ <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			var result = prompt("Unsaved changes have been made.  Do you want to" + <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								" leave the page?  Enter 'Yes' to continue.", ""); <br /><br />

			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			if (result == null) <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			{ <br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				e.set_cancel(true); <br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				return; <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			} <br /><br />

			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			while (result != "yes") <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			{
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				result = prompt("Enter 'Yes' to continue.", ""); <br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				if (result == null) <br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				{ <br />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					e.set_cancel(true); <br />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					return; <br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				} <br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			} <br />
		}
	</p>

	<br />

	<p>
		<mw:CustomAlertBehavior ID="cabTestAlert" runat="server"
			ClientNotifyFunction="verifyExit" />

		<asp:CheckBox Text="Test CheckBox Control" ID="cbTest" runat="server" />
		<mw:CheckBoxModWatcherExtender TargetControlID="cbTest" runat="server" />

		<br /><br />

		<asp:Button Text="Fire ModAlert" ID="btnTest" runat="server" />
		<mw:OnClickModAlertExtender runat="server"
			TargetControlID="btnTest" AlertBehaviorID="cabTestAlert" />

		<asp:Button Text="Save Changes" OnClick="btnSave_Click" ID="btnSave" runat="server" />

		<br /><br />
		
		Page last served: <asp:Label ID="lblLastServed" runat="server"></asp:Label>
		<br />
		Change detected on server? <asp:Label ID="lblServerChange" runat="server"></asp:Label>
	</p>

</asp:Content>
